﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TopModel;
using System.Web.Security;
using TopUtility;
using Top.Api;
using Top.Api.Request;
using Top.Api.Response;
using System.Configuration;
using Top.Api.Domain;
public partial class MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!IsPostBack)
        //{
        //    Member member = ((MemberRepository)Page.User).Identity as Member;
        //    hMsg.InnerText = "欢迎 " + member.Name;
        //    aUserName.InnerText = member.Name;
        //}
    }


    protected void lbtnLoginOut_Click(object sender, EventArgs e)
    {
        FormsAuthentication.SignOut();
        Response.Redirect("Login.aspx");
    }

    protected void btnImport_Click(object sender, EventArgs e)
    {
        TopTradeHelper tradeHelper = new TopModel.TopTradeHelper();
        TraderatesGetResponse rspRate = new TraderatesGetResponse();
        TradeFullinfoGetResponse rspTrade = new TradeFullinfoGetResponse();
        try
        {
            ITopClient topClient = new DefaultTopClient(ConfigurationManager.AppSettings["TopInterfaceUrl"], ConfigurationManager.AppSettings["TopAppKey"], ConfigurationManager.AppSettings["TopAppSecret"], "xml");
            TraderatesGetRequest reqRate = new TraderatesGetRequest();
            TradeFullinfoGetRequest reqTrade = new TradeFullinfoGetRequest();
            reqRate.Fields = "tid,item_title,content,result,oid";
            reqRate.RateType = "give";
            //req.Result = type.ToString();
            reqRate.Role = "buyer";
            rspRate = topClient.Execute(reqRate, Session["TopSession"].ToString());
            reqTrade.Fields = "seller_nick,buyer_nick,receiver_name,receiver_state,receiver_city,receiver_district,receiver_mobile,receiver_phone";
            foreach (TradeRate rate in rspRate.TradeRates)
            {
                reqTrade.Tid = rate.Tid;
                rspTrade = topClient.Execute(reqTrade, Session["TopSession"].ToString());
                tradeHelper.AddTopTrade(rspTrade.Trade, rate);
            }
        }
        catch (Exception ex)
        {
            Utility.GoError(Context, "导入数据失败，请联系开发商");
        }
    }
}
